package com.hspedu.newData.LCR;

import org.junit.Test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-26 
 * @Version: 1.0
 */

public class LCR110所有可达路径 {

    List<List<Integer>> res = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();

    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {

        path.add(0);
        dfs(graph,0, graph.length-1);
        return res;
    }

    public void dfs(int[][] graph,int x,int n){

        if (x==n){
            res.add(new ArrayList<>(path));
            return;
        }

        for (int i : graph[x]) {
            path.add(i);
            dfs(graph,i,n);
            path.removeLast();
        }
    }

    @Test
    public void test() {
        // 测试代码
        List<List<Integer>> lists = allPathsSourceTarget(new int[][]{{1, 2}, {3}, {3}, {}});
        System.out.println("111");
    }
}
